#pragma once
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
#include<ctype.h>
#include<string.h>
#include "CountingSort.h"

const int size = 15;
Element elearray[size];
Element * newarray;

void generateEleArray()
{
	srand(time(NULL));
	for (int index = 0; index < size; index++)
	{
		elearray[index].key = (int)((rand() * 1.0 / RAND_MAX) * 9 + 1);
		char datachar = (char)((rand() * 1.0 / RAND_MAX) * 49 + 64);
		char datastring[30] = "This is information    ";		
		datastring[20] = datachar;
		datastring[22] = '\0';
		strcpy(elearray[index].data, datastring);
	}//end loop
}//end method

void printElements(Element * elearray, int arraysize)
{
	for (int index = 0; index < arraysize; index++)
	{
		printf("Element %d: ", index);
		printf("Key value %d, data: \n", elearray[index].key);
		printf("%s\n", elearray[index].data);
	}//end loop

	printf("\n");
}//end method

int main()
{
	generateEleArray();
	printf("Before sorting,data:\n");
	printElements(elearray, 15);

	CountingSort countingsort(elearray, 15);
	newarray = countingsort.sortarray();
	printf("After sorting,data:\n");
	printElements(newarray, 15);

	system("pause");
	return 0;
}//end main function